package com.qumitech.visualnovel.model.dao.editor;

import java.util.Date;
import com.alibaba.fastjson.*;

public class ResourceDAO {
    private Long id;

    private Long relationId;

    private Long bookId;

    private Integer uid;

    private String maintype;

    private String subtype;

    private String decorationType;

    private String sexIfPicture;

    private String status;

    private String name;

    private String path;

    private String attribute;

    private Boolean ifDelete;

    private Date updatedAt;

    private Date createdAt;

    private String relations;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getRelationId() {
        return relationId;
    }

    public void setRelationId(Long relationId) {
        this.relationId = relationId;
    }

    public Long getBookId() {
        return bookId;
    }

    public void setBookId(Long bookId) {
        this.bookId = bookId;
    }

    public Integer getUid() {
        return uid;
    }

    public void setUid(Integer uid) {
        this.uid = uid;
    }

    public String getMaintype() {
        return maintype;
    }

    public void setMaintype(String maintype) {
        this.maintype = maintype == null ? null : maintype.trim();
    }

    public String getSubtype() {
        return subtype;
    }

    public void setSubtype(String subtype) {
        this.subtype = subtype == null ? null : subtype.trim();
    }

    public String getDecorationType() {
        return decorationType;
    }

    public void setDecorationType(String decorationType) {
        this.decorationType = decorationType == null ? null : decorationType.trim();
    }

    public String getSexIfPicture() {
        return sexIfPicture;
    }

    public void setSexIfPicture(String sexIfPicture) {
        this.sexIfPicture = sexIfPicture == null ? null : sexIfPicture.trim();
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status == null ? null : status.trim();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path == null ? null : path.trim();
    }

    public String getAttribute() {
        return attribute;
    }

    public void setAttribute(String attribute) {
        this.attribute = attribute == null ? null : attribute.trim();
    }

    public Boolean getIfDelete() {
        return ifDelete;
    }

    public void setIfDelete(Boolean ifDelete) {
        this.ifDelete = ifDelete;
    }

    public Date getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Date updatedAt) {
        this.updatedAt = updatedAt;
    }

    public Date getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Date createdAt) {
        this.createdAt = createdAt;
    }

    public String getRelations() {
        return relations;
    }

    public void setRelations(String relations) {
        this.relations = relations;
    }

    private void setJSPath(String path) {
        JSONArray result = new JSONArray();
        result.add(path);
        this.path = result.toJSONString();
    }

    private void addJSPath(String path) {
        JSONArray result = this.path==null || this.path.length()==0 ? new JSONArray() : JSONArray.parseArray(this.path);
        result.add(path);
        this.path = result.toJSONString();
    }

    private void setJSAttribute(String name, Long duraition) {
        JSONArray result = new JSONArray();
        JSONObject jItem = new JSONObject();
        jItem.put("name", name);
        jItem.put("duraition", duraition);
        result.add(jItem);
        this.attribute = result.toJSONString();
    }

    private void addJSAttribute(String name, Long duraition) {
        JSONArray result = this.attribute==null || this.attribute.length()==0 ? new JSONArray() : JSONArray.parseArray(this.attribute);
        JSONObject jItem = new JSONObject();
        jItem.put("name", name);
        if (duraition!=null) jItem.put("duraition", duraition);
        result.add(jItem);
        this.attribute = result.toJSONString();
    }

    public void retainAddAttribute(String attName, String attValue) {
        JSONArray result = this.attribute==null || this.attribute.length()==0 ? new JSONArray() : JSONArray.parseArray(this.attribute);
        if (result.size() == 0) result.add(new JSONObject());
        JSONObject jItem = result.getJSONObject(0);
        jItem.put(attName, attName.equals("duraition") ? Long.valueOf(attValue) : attValue);
        this.attribute = result.toJSONString();
    }

    public void setRecord(String name, String path, Long duraition) {
        this.name = name;
        this.setJSPath(path);
        this.setJSAttribute(name, duraition);
    }

    public void addRecord(String name, String path, Long duraition) {
        this.name = name;
        this.addJSPath(path);
        this.addJSAttribute(name, duraition);
    }

    public void retainAddRecord(String name, String path, Long duraition) {
        this.name = name;
        this.setJSPath(path);
        this.retainAddAttribute("name", name);
        if (duraition != null) this.retainAddAttribute("duraition", String.valueOf(duraition));
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", relationId=").append(relationId);
        sb.append(", uid=").append(uid);
        sb.append(", maintype=").append(maintype);
        sb.append(", subtype=").append(subtype);
        sb.append(", decorationType=").append(decorationType);
        sb.append(", sexIfPicture=").append(sexIfPicture);
        sb.append(", status=").append(status);
        sb.append(", name=").append(name);
        sb.append(", path=").append(path);
        sb.append(", attribute=").append(attribute);
        sb.append(", ifDelete=").append(ifDelete);
        sb.append(", updatedAt=").append(updatedAt);
        sb.append(", createdAt=").append(createdAt);
        sb.append("]");
        return sb.toString();
    }
}
